package com.cy.store.service.impl;

import com.cy.store.entity.Address;
import com.cy.store.entity.Product;
import com.cy.store.mapper.AddressMapper;
import com.cy.store.mapper.ProductMapper;
import com.cy.store.service.IAddressService;
import com.cy.store.service.IDistrictService;
import com.cy.store.service.IProductService;
import com.cy.store.service.ex.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProductServImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> findHotList() {
        List<Product> list = productMapper.findHotProduct();
        //将不需要的数据设置为null返回给前端，减少流量传输提高效率
        for (Product product:list) {
            product.setPriority(null);
            product.setCreatedTime(null);
            product.setCreatedUser(null);
            product.setModifiedTime(null);
            product.setCreatedUser(null);
        }
        return list;
    }

    @Override
    public Product getProductDetails(Integer id) {
        Product result = productMapper.getProductDetails(id);
        if(result==null){
            throw new ProductNotExistException("商品信息不存在！");
        }
        result.setPriority(null);
        result.setCreatedTime(null);
        result.setCreatedUser(null);
        result.setModifiedTime(null);
        result.setCreatedUser(null);
        return result;
    }
}
